﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GONES.Tools.Common;
using GONES.Model;
using Spring.Context;
using Spring.Context.Support;
using GONES.IBLL;

public partial class _Default : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(GetSessionbyName("LoginInfo")))
            Response.Redirect("Login.aspx");
    }

    public  string  BuilderMenu()
    {
        IApplicationContext appContext = ContextRegistry.GetContext();
        var navManager = appContext.GetObject("S_NavManager") as IS_NavManager;
        LoginInfo loginInfo = (LoginInfo)Session["LoginInfo"];
        IList<S_Nav> navParentList = navManager.GetParentNavListByUserId(loginInfo.UserId);
        IList<S_Nav> navList = navManager.GetNavListByUserId(loginInfo.UserId);
        string menustr = "";
        for (int i = 0; i < navParentList.Count; i++)
        {
            menustr += string.Format(" <div class=\"accordionHeader\"><h2><span>{0}</span>{1}</h2></div>", "Folder", navParentList[i].Title);
            CreateChildMenu(ref menustr, navList);
        }
        return menustr;
    }

    private void CreateChildMenu(ref string menustr, IList<S_Nav> navList)
    {
        menustr += "<div class=\"accordionContent\"><ul class=\"tree treeFolder\">";
        for (int i = 0; i < navList.Count; i++)
        {
            menustr += string.Format("<li><a href=\"{0}\" target=\"navTab\" rel=\"{1}\">{2} </a></li>", navList[i].Url, navList[i].Ptag.Trim(), navList[i].Title);
        }
        menustr += " </ul></div>";
    }
    public string GetSessionbyName(string sessionname)
    {
        string sessionvalue = "";
        try
        {
            sessionvalue = HttpContext.Current.Session[sessionname].ToString().Trim();
        }
        catch
        {

        }
        return sessionvalue;
    }
    protected void linkOut_Click(object sender, EventArgs e)
    {
        Session.RemoveAll();
        Response.Redirect("Login.aspx");
    }
}